package com.orion.controller;

import com.orion.entity.Result;
import com.orion.service.TestFeignHystrixService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 测试hystrix
 *
 * @author Administrator
 * @date 2021/10/30
 */
@RestController
@RequestMapping("/hystrix")
public class TestFeignHystrixController {

    @Value("${server.port}")
    private Integer port;

    @Resource
    private TestFeignHystrixService testFeignHystrixService;

    //http://127.0.0.1:8001/hystrix/providerHystrix
    @GetMapping("/providerHystrix")
    public Result providerHystrix(@RequestHeader("mitch") String mitch,
                                  @CookieValue("orion") String cookieParamOrion,
                                  @RequestParam String marit) {
        String predicate = "test provider hystrix : port : " + port
                + " -- cookie: orion = " + cookieParamOrion
                + " -- param : marit = " + marit
                + " -- header mitch = " + mitch;
        Result r = testFeignHystrixService.providerHystrix();
        r.setData(r.getData() + "--*******--" + predicate);
        return r;
    }

    //http://127.0.0.1:8001/hystrix/providerPartHystrix
    @GetMapping("/providerPartHystrix")
    public Result providerPartHystrix(@RequestHeader("mitch") String mitch,
                                      @CookieValue("orion") String cookieParamOrion,
                                      @RequestParam String marit) {
        String predicate = "test provider part hystrix : port : " + port
                + " -- cookie: orion = " + cookieParamOrion
                + " -- param : marit = " + marit
                + " -- header mitch = " + mitch;
        Result r = testFeignHystrixService.providerPartHystrix(1);
        r.setData(r.getData() + "--*******--" + predicate);
        return r;
    }

    //http://127.0.0.1:8001/hystrix/providerPartCircuit
    @GetMapping("/providerPartCircuit")
    public Result providerPartCircuit(@RequestHeader("mitch") String mitch,
                                      @CookieValue("orion") String cookieParamOrion,
                                      @RequestParam String marit) {
        String predicate = "test provider part circuit : port : " + port
                + " -- cookie: orion = " + cookieParamOrion
                + " -- param : marit = " + marit
                + " -- header mitch = " + mitch;
        Result r = testFeignHystrixService.providerPartCircuit(1);
        r.setData(r.getData() + "--*******--" + predicate);
        return r;
    }
}
